<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <!--{include file='comm/header.tpl'}-->
    <title>咖啡验收列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</head>

<body>

<style>
    .imageSites{
        position: absolute;
        left:275px;
        top:8px;
    }
    .search_option_drop{
        width:300px;
    }

</style>


<div class="container">

    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                            <span>
                               验收日期：<input type="text"  class="form-control input-sm" name="accept_date" id="accept_date" readonly="readonly" style="width:150px;"/>
                            </span>
                            <span>
                                <button type="button" class="btn btn-primary" id="searchBtn" onclick="coffeeSetting.search();">查询</button>
                            </span>
                            <span>
                                <button type="button" class="btn btn-warning" id="clearBtn" onclick="coffeeSetting.clearUp();" >重置</button>
                            </span>
                    </form>
                </div>
            </div>
            <div id="pop" style="display: none;height: 500px;">
                <form id="categoryForm" class="form-horizontal" role="form" onsubmit="return false;">
                    <input type="hidden" id="itemCategoryID" name="itemCategoryID" value=""/>
                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="company_name">
                            <span class="red">*</span>
                            日期：
                        </label>
                        <div class="col-sm-9">
                            <input class="form-control w150" type="text" id="accept_date"  name="accept_date"readonly="readonly"  value="<!--{$send_date}-->">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="company_name">
                            <span class="red">*</span>
                            配送站：
                        </label>
                        <div class="col-sm-9">
                            <select class="form-control w150" id="distribution_id" name="distribution_id">
                                <option value="">请选择</option>
                                <option value="48">静安寺</option>

                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="company_name">
                            <span class="red"></span>
                            备注：
                        </label>
                        <div class="col-sm-9">

                            <textarea class="form-control w300"  placeholder="请输入备注" name="remark" id="remark"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                     <hr>
                        <b>咖啡明细：<input type="button" value="+" class="btn btn-primary" onclick="coffeeSetting.addx();"></b>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="company_name">
                            <span class="red">*</span>
                            咖啡编号：
                        </label>
                        <div class="col-sm-9">

                            <select class="form-control fl"  name="coffeesku[]" style="width: 100px;margin-right: 5px;">
                                <option value="">请选择...</option>

                                <!--{foreach from=$coffeeInfo item=pic key=k}-->
                                <option value="<!--{$pic->product_code}-->"><!--{$pic->goodsName}--></option>
                                <!--{/foreach}-->
                            </select>
                            <label class="col-sm-3 control-label"  style="width: 100px;margin-right: 5px;" for="company_name">
                                <span class="red">*</span>数量：
                            </label>
                            <input class="form-control fl" style="width: 100px;margin-right: 5px;" type="text"   placeholder="请输入数量" name="coffeenum[]">

                        </div>
                    </div>





                </form>
            </div>





            <div id="poq" style="display: none;height: 500px;">
            </div>




            <table id="flex" style="display:none"></table>
        </div>
    
</div>
<script type="text/javascript">
$("#accept_date").datepicker();
$("#flex").flexigrid({
    url:"/invokingAjax-backend/dunch/dunch.ajax?operFlg=101",
    dataType: "json",
    colModel : [
       // {display: "操作", width : 100, align: "center"},
       // {display: "验收ID", width : 100, align: "center"},
        {display: "验收人", width : 100, align: "center"},
        {display: "验收日期", width : 150, align: "center"},
        {display: "项目名称", width : 100,align:"left"},
        {display: "配送站", width : 100,align:"left"},
        {display: "咖啡验收明细", width : 300,align:"left"},
        {display: "验收备注", width : 140,align:"left"}

    ],
    buttons : [
        {name: "添加", bclass: "add", onpress : "coffeeSetting.add"}
    ],
    sortname: "createTime",
    sortorder: "desc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    }
});

var coffeeSetting= {

    itemCategoryID:'',
    itemID:'',
    selected:'',
    //搜索
    search: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();
    },
    //添加分类信息
    add: function() {
        E.popup.open({
            id:"pop",                  //获取id为"pop"元素内的HTML
            title:"添加咖啡验收信息",       //弹出层标题
            css: "width:550px;hight:550px;",   //设置弹出层样式
            btnName: "保存",        //执行“确定”操作的按钮名称
            btnCall:"coffeeSetting.checkInfo();"  //点击确定后执行的方法
        });





    },
    //添加选项信息
    addx:function(){
        var text='';
        <!--{foreach from=$coffeeInfo item=pic key=k}-->
        text+="<option value='<!--{$pic->product_code}-->'><!--{$pic->goodsName}--></option>";
        <!--{/foreach}-->

        var coffeHtml='<div class="form-group">' +
                '<label class="col-sm-3 control-label" for="company_name"><span class="red">*</span> 咖啡编号：</label>' +
                '<div class="col-sm-9">' +
                '<select class="form-control fl"  name="coffeesku[]" style="width: 100px;margin-right: 5px;">' +
                '<option value="">请选择...</option>' +
                text+
                '</select>' +
                '<label class="col-sm-3 control-label"  style="width: 100px;margin-right: 5px;" for="company_name">' +
                '<span class="red">*</span>数量：' +
                '</label>' +
                '<input class="form-control fl" style="width: 100px;margin-right: 5px;" type="text"   placeholder="请输入数量" name="coffeenum[]">' +
                '  <input class="btn btn-warning" value="-" type="button"  name="j" onclick="coffeeSetting.delx(this);">'+
                '</div>' +
                '</div>';

        $("#categoryForm").append(coffeHtml);

    },
    //删除选项信息
    delx:function(t){
       var zzzz= $(t).parents().parents(".form-group").remove();
    },
    //验证分类信息
    checkInfo:function(){
        var data = E.getFormValues("categoryForm");
        var error_msg = "";

        if (data.accept_date == ''){
            error_msg += '日期不能为空<br/>';
        }
        if (data.distribution_id == ''){
            error_msg += '配送站不能为空<br/>';
        }
        var coffee_error='';
        $("select[name^='coffeesku']").each(function(){
            if($(this).val()==''){
                coffee_error = '咖啡编号不能为空<br/>';
            }
        })
        var num_error='';
        $("input[name^='coffeenum']").each(function(){
            if($(this).val()==''){
                num_error += '数量不能为空<br/>';
            }
        })
        if(coffee_error){
            error_msg += '咖啡编号不能为空<br/>';
        }
        if(num_error){
            error_msg += '数量不能为空<br/>';
        }
        if (error_msg != ""){
           E.alert(error_msg);
        }else{
        E.confirm('您确认添加分类吗?', "coffeeSetting.addExe");
        }
    },
    //执行 添加
    addExe: function() {
        //弹出遮罩层
        E.loadding.open("执行中……");
        //获取表单参数
        var data = E.getFormValues('categoryForm');
        jquery_ajax(100,data,coffeeSetting.callback);
        //关闭弹出层
        E.popup.close();
        //关闭遮罩层
        E.loadding.close();
    },
    /**
     * 编辑分类
     */
    edit: function( accept_id ) {
        E.loadding.open("正在查询，请稍后...");
        E.ajax_post({
            url:"/invokingAjax-backend/dunch/dunch.ajax?operFlg=102",
            data:{accept_id:accept_id},
            call:"coffeeSetting.editResult"
        });
        //显示弹出层
        E.popup.open({
            id:"poq",
            title: "咖啡验收明细",
            css: "width:550px;"

        });

    },
    //查询结果
    editResult:function(o){
        E.loadding.close();
        if( o.code != 200 ){
            E.alert( o.message );
            return false;
        }
        var data = o.data;

        $(".popup-content").html(data);


    },
    //修改验证
    editCheck:function(){
        var data = E.getFormValues("categoryForm");
//        var error_msg = '';
//        //验证分类名称
//        if (data.itemCategoryName == ''){
//            error_msg += '分类名称不能为空<br/>';
//        }
//        if (error_msg != ""){
//            E.alert(error_msg);
//        }else{
        E.confirm('您确认修改分类吗?', "coffeeSetting.editExe");
//        }

    },
    //编辑执行
    editExe:function(){
        //弹出遮罩层
        E.loadding.open("正在执行，请稍后...");
        //获取表单参数
        var data = E.getFormValues('categoryForm');
        jquery_ajax(4,data,coffeeSetting.callback);
        //关闭弹出层
        E.popup.close();
        //关闭遮罩层
        E.loadding.close();
    },


    //删除选项分类
    delPackge:function( package_id ){
        //this.selected = $( thisObj ).parents("tr");
        this.package_id = package_id;
        E.confirm('您确认删除该分类选项吗?','coffeeSetting.delExe');
    },

    delExe:function(){
        $.ajax({
            type: "POST",
            url: "/invokingAjax-backend/dunch/dunch.ajax?operFlg=5",
            dataType: "JSON",
            data:{
                package_id: this.package_id
            },
            success: function(result_obj){
                if (result_obj.code == 200) {
                    E.alert(result_obj.message, 2);
                    $("#flex").flexReload();

                }
                else {
                    E.alert(result_obj.message);
                }
            }
        });
    },

    //回调函数
    callback: function( obj ) {
        E.loadding.close();
        E.popup.close();
        if( obj.code == 200 ){
            E.alert( obj.message , 2 , 'coffeeSetting.load');
        }else{
            E.alert(obj.message);
        }
    },
    load: function() {
        $("#flex").flexReload();
    },
    //重置分类名称
    clearUp:function() {
        $("#accept_date").val('');
        coffeeSetting.load();
    }
};
function jquery_ajax(flg,data,func){
    $.ajax({
        type: "post",
        url: "/invokingAjax-backend/dunch/dunch.ajax?operFlg="+flg,
        dataType: "json",
        data: data,
        success: function( result_obj ) {
            func(result_obj);
        },
        error : function(msg){
            alert('网络不给力，请重新尝试...');
        }
    });
}


//绑定上传图片
KindEditor.ready(function(K) {

    var kindEditor_upload = K.editor({
        allowFileManager : true,
        uploadJson: '/framework/kindeditor/php/upload_json.php?act=system'
    });

    $(document).on('click', '#update_logo', function() {

        kindEditor_upload.loadPlugin('image', function() {
            kindEditor_upload.plugin.imageDialog({
                showRemote : false,
                clickFn : function(url) {

                    $('#logo_img_box').html('<img style="width:110px;height: 110px;" src="' + url + '"> <a href="javascript: void(0);" id="del_log_img">删除</a>').show();
                    $('#itemName').val(url);
                    kindEditor_upload.hideDialog();

                }
            });
        });

    });

    $(document).on('click', '#del_log_img', function() {
        $('#logo_img_box').html('').hide();
        $('#itemName').val('');
    });

});

</script>
</body>
</html>